home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / testcpp / 12 / test.g < prev   
Encoding:
Text File  |  1995-03-10  |  1.0 KB  |  39 lines  |  [TEXT/MPS ]

  1. /* This is test.g which tests a simple DLG-based scanner using string input */
  2.  
  3. <<
  4. typedef ANTLRCommonToken ANTLRToken;
  5.  
  6. #include "DLGLexer.h"
  7.  
  8. int main(int argc, char **argv)
  9. {
  10.     if ( argc==1 ) {fprintf(stderr, "how about an argument?\n"); exit(1);}
  11.     DLGStringInput in(argv[1]);    /* create an input stream for DLG */
  12.     DLGLexer scan(&in,2000);/* create scanner reading from stdin with bufsize==2000 */
  13.     ANTLRTokenBuffer pipe(&scan);    /* make a buffered pipe between lexer & parser */
  14.     ANTLRToken aToken;        /* create a token to fill in for DLG */
  15.     scan.setToken(&aToken);
  16.     Expr parser(&pipe);        /* create a parser of type Expr hooked to the scanner */
  17.     parser.init();            /* init the parser; prime lookahead etc... */
  18.  
  19.     parser.e();                /* start parsing at rule 'e' of that parser */
  20.     return 0;
  21. }
  22. >>
  23.  
  24. #token "[\ \t\n]+"    <<skip();>>
  25. #token Eof "@"
  26.  
  27. #tokclass My { IDENTIFIER NUMBER }
  28.  
  29. class Expr {                /* Define a grammar class */
  30.  
  31. e    :    My My Eof
  32.         <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
  33.     ;
  34.  
  35. }
  36.  
  37. #token IDENTIFIER    "[a-z]+"
  38. #token NUMBER        "[0-9]+"
  39.